import { Component, OnInit,Output,Input,EventEmitter } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from '../../services/pages.service';
import { UtilService } from '../../services/util.service';
import { RequestService } from '../../services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-pua',
  templateUrl: './pua.component.html',
  styleUrls: ['./pua.component.scss']
})
export class PuaComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService,public request:RequestService) {
    
  }

  @Output()  private  outer=new EventEmitter();
  @Input() puc_msg:any; 


  progress_list;
  pucType_list;
  acReqd_list;
  prcSite_list;
  isCms_list;
  drDiffJgd_list;
  multiImpl_list;
  implByIns_list;
  puBrdgMode_list;
  isPuItmd_list;
  isSpot_list;
  psStlMthd_list;
  splEnabled_list;
  rqdCtrl_list;
  gmEnabled_list;
  bxiEnabled_list;
  mfzEnabled_list;
  psMfzSite_list;
  planCtrl_list;
  srcDocType_list;
  ordType_list;
  delivMthd_list;
  psaCtlr_list;
  slcAutoGen_list;
  slcAutoChk_list;
  pucAutoGen_list;
  slcGen_list;
  pucAutoChk_list;
  isSlItmd_list;
  effective_list;
  suspended_list;
  cancelled_list;
  renewed_list;
  slCtrl_list;
  slFwdd_list;
  
  vdrInvd_list;

  ngOnInit() {
    setTimeout(()=>{ 
      this.interfaceService.postPage("/erp/purchase/puc/option", {}).subscribe((data0: any) => {//手动下拉
        if (this.interfaceService.codeValidation(data0)) {
        if (data0.code == 200) {
          var sele = data0.object;
          this.progress_list = sele.progress;//进度
          /* this.pucType_list = sele.pucType;//采购合同类别
          this.acReqd_list = sele.acReqd;//绑定附加成本
          this.prcSite_list = sele.prcSite;//定价点
          this.isCms_list = sele.isCms;//是否代销
          this.drDiffJgd_list = sele.drDiffJgd;//差异裁定方
          this.multiImpl_list = sele.multiImpl;//多次执行
          this.implByIns_list = sele.implByIns;//按指令执行
          this.puBrdgMode_list = sele.puBrdgMode;//采购桥接方式
          this.isPuItmd_list = sele.isPuItmd;//是否居间采购
          this.isSpot_list = sele.isSpot;//是否现货
          this.psStlMthd_list = sele.psStlMthd;//结算方式
          this.splEnabled_list = sele.splEnabled;//允许增补商品
          this.rqdCtrl_list = sele.rqdCtrl;//货期控制
          this.gmEnabled_list = sele.gmEnabled;//启用保证金
          this.bxiEnabled_list = sele.bxiEnabled;//启用配码
          this.mfzEnabled_list = sele.mfzEnabled;//启用冻款
          this.psMfzSite_list = sele.psMfzSite;//冻款点
          this.planCtrl_list = sele.planCtrl;//计划控制
          this.srcDocType_list = sele.srcDocType;//原始单据类别
          this.ordType_list = sele.ordType;//订单类别
          this.delivMthd_list = sele.delivMthd;//送货方式
          this.psaCtlr_list = sele.psaCtlr;//控制协议方
          this.slcAutoGen_list = sele.slcAutoGen;//销售合同自动生成
          this.slcAutoChk_list = sele.slcAutoChk;//销售合同自动审核
          this.pucAutoGen_list = sele.pucAutoGen;//采购合同自动生成
          this.slcGen_list = sele.slcGen;//销售合同已生成
          this.pucAutoChk_list = sele.pucAutoChk;//采购合同自动审核
          this.isSlItmd_list = sele.isSlItmd;//是否居间销售
          this.effective_list = sele.effective;//已生效
          this.suspended_list = sele.suspended;//挂起
          this.cancelled_list = sele.cancelled;//撤销
          this.renewed_list = sele.renewed;//已递延
          this.slCtrl_list = sele.slCtrl;//销售控制
          this.slFwdd_list = sele.slFwdd;//已转销
          this.vdrInvd_list=sele.vdrInvd;//供应商是否介入 */
        }
      }
      });
    },500);
  }

  unitStatus_list=JSON.parse(localStorage.getItem("unitStatus_list"))
  prodStatus_list=JSON.parse(localStorage.getItem("prodStatus_list"))
  popup01_url='';
  popup01_switchUnitId='';
  popup01 = false;
  popup01_show(url,switchUnitId?): void {
    this.popup01_url=url
    this.popup01_switchUnitId=switchUnitId;
    this.popup01 = true;
    this.popup01_table();
  }
  popup01_hide(): void {
    this.popup01 = false;
    this.popup01_url='';
    this.popup01_ss1='';
    this.popup01_ss2='';
    this.popup01_ss3=''; 
    this.popup01_ss4=''; 
    this.popup01_ss5 = '';
    this.popup01_ss6 = null;
  }

  venderIdss='';
  popup01_ss1='';
  popup01_ss2='';
  popup01_ss3='';
  popup01_ss4='';
  popup01_ss5 = '';
  popup01_ss6 = null;
  popup01_table(){
    if(this.popup01_ss6==null){
      this.popup01_listTable("/erp/purchase/pua/list"+"?1=1&switchUnitId="+this.popup01_switchUnitId+"&effective=T&puaNum="+this.popup01_ss1+"&startTime="+this.popup01_ss2+"&endTime="+this.popup01_ss3+"&venderNum="+this.popup01_ss4+"&rcvWarehNum="+this.popup01_ss5+"&progress=");
    }else{
      this.popup01_listTable("/erp/purchase/pua/list"+"?1=1&switchUnitId="+this.popup01_switchUnitId+"&effective=T&puaNum="+this.popup01_ss1+"&startTime="+this.popup01_ss2+"&endTime="+this.popup01_ss3+"&venderNum="+this.popup01_ss4+"&rcvWarehNum="+this.popup01_ss5+"&progress="+this.popup01_ss6);
    }
    
  }

  popup01_listTable(url):void{
    setTimeout(()=>{ 
      layui.use(['table', 'laydate'], (obj)=>{
        var  table = layui.table, laydate = layui.laydate;
        laydate.render({
          elem: '#date52'
          ,done: (value) => {
          this.popup01_ss2=value; 
          }
        });
        laydate.render({
          elem: '#date62'
          ,done: (value) => {
          this.popup01_ss3=value; 
          }
        });
        
        table.render({
          elem: '#popup01_tblist_pua'
          ,height: this.utilService.height
          ,width:680
          ,url: url
          ,page: true //开启分页
          ,limit:1000
          ,limits:this.utilService.limits
          ,title: '数据表'
          ,cellMinWidth: 100
          ,cols: [[
            { title: '序号', type: 'numbers', fixed: 'left' }
            , { field: 'prodCatId', title: ' 商品分类id', hide: true,width:100 }
            , { field: 'prodId', title: ' 商品ID', hide: true,width:100 }
            , { field: 'puaNum', title: '采购申请号' }
            , { field: 'psxNum', title: '购销申请号' }
            , { field: 'docDate', title: '单据日期' }
            , { field: 'puaType', title: '采购申请类别' }
            , { field: 'delivWarehNum', title: '发货仓库编号' }
            , { field: 'delivWarehName', title: '发货仓库名称' }
            , { field: 'deptNum', title: '部门编号' }
            , { field: 'deptName', title: '部门名称' }
            , { field: 'stUnitNum', title: '始发方编号' }
            , { field: 'stUnitName', title: '始发方名称' }
            , { field: 'stWarehNum', title: '始发仓库编号' }
            , { field: 'stWarehName', title: '始发仓库名称' }
            , { field: 'puaAutoGen', title: '采购申请自动生成' }
            , { field: 'puaAutoChk', title: '采购申请自动审核' }
            , { field: 'venderNum', title: '供应商编号' }
            , { field: 'venderName', title: '供应商名称' }
            , { field: 'rcvWarehNum', title: '收货仓库编号' }
            , { field: 'rcvWarehName', title: '收货仓库名称' }
            , { field: 'endUnitNum', title: '转送方编号' }
            , { field: 'endUnitName', title: '转送方名称' }
            , { field: 'endWarehNum', title: '转送仓库编号' }
            , { field: 'endWarehName', title: '转送仓库名称' }
            , { field: 'vdrInvd', title: '供应商介入' }
            , { field: 'slaAutoGen', title: '销售申请自动生成' }
            , { field: 'slaGen', title: '销售申请已生成' }
            , { field: 'slaAutoChk', title: '销售申请自动审核' }
            , { field: 'rqdCtrl', title: '货期控制' }
            , { field: 'prodCatId', title: '商品分类ID' }
            , { field: 'prodCatName', title: '商品分类名称' }
            , { field: 'ordType', title: '订单类别' }
            , { field: 'reqdDate', title: '货期' }
            , { field: 'bxiEnabled', title: '启用配码' }
            , { field: 'ttlQty', title: '总数量' }
            , { field: 'ttlBox', title: '总箱数' }
            , { field: 'ttlVal', title: '总金额' }
            , { field: 'ttlMkv', title: '总市值' }
            , { field: 'oprCode', title: '操作员代码' }
            , { field: 'oprName', title: '操作员姓名' }
            , { field: 'opTime', title: '操作时间' }
            , { field: 'chkrNum', title: '审核人编号' }
            , { field: 'chkrName', title: '审核人姓名' }
            , { field: 'chkTime', title: '审核时间' }
            , { field: 'effective', title: '已生效' }
            , { field: 'progress', title: '进度' }
            , { field: 'suspended', title: '挂起' }
            , { field: 'cancelled', title: '撤销' }
            , { field: 'remarks', title: '备注' }
            ]]
          ,request: {
            pageName: 'page' //页码的参数名称，默认：page
            ,limitName: 'size' //每页数据量的参数名，默认：limit
          }
          ,parseData: function(res){ //res 即为原始返回的数据
            return {
              "code": res.code, //解析接口状态
              "msg": res.message, //解析提示文本
              "count": res.object.total, //解析数据长度
              "data": res.object.list //解析数据列表
            }
          }
          ,response: {
            statusCode: 200 //规定成功的状态码，默认：0
            ,dataName: 'data' //规定数据列表的字段名称，默认：data
          } 
        });
        table.on('rowDouble(popup01_tblist_pua)', (obj)=>{
          this.popup01_hide();
          this.outer.emit(obj.data)       
         });
        
      });
      
    },50);
  
  }




  popup1_id
  popup1 = false;
  popup1_show(id?): void {
    this.popup1_id=id
    this.popup1 = true;
    this.popup1_table();
  }
  popup1_hide(): void {
    this.popup1 = false;
    this.popup1_ss1='';
    this.popup1_ss2='';
    this.popup1_ss3=''; 
    this.popup1_ss4=''; 
  }

  popup1_ss1='';
  popup1_ss2='';
  popup1_ss3='';
  popup1_ss4='';
  popup1_table(){
    this.popup1_listTable("/erp/unit/option/unitOption?unitType=VD"+"&unitCode="+this.popup1_ss1+"&unitName="+this.popup1_ss2+"&inputCode="+this.popup1_ss3+"&unitStatus="+this.popup1_ss4 + "&switchUnitId=" + this.popup01_switchUnitId);
  }

  popup1_listTable(url):void{
    setTimeout(()=>{ 
      layui.use(['table'], (obj)=>{
        var  table = layui.table
        
        table.render({
          elem: '#popup1_tblist_pua'
          ,height: this.utilService.height
          ,width:680
          ,url: url
          ,page: true //开启分页
          ,limit:1000
          ,limits:this.utilService.limits
          ,title: '数据表'
          ,cellMinWidth: 100
          ,cols: [[
			{title: '序号', type: 'numbers',fixed: 'left'},
            {field: 'unitCode', title: '组织代码', sort: true}
			  ,{field: 'unitId', title: '组织id',hide:true} 
			  ,{field: 'unitName', title: '组织名称'} 
			  ,{field: 'inputCode', title: '助记码'}
			  ,{field: 'telNum', title: '电话号码'}
			  ,{field: 'address', title: '地址'}
			  ,{field: 'lmCode', title: '联系人姓名'}
			  ,{field: 'unitStatus', title: '组织状态',
				templet: (d) => {
				  return this.utilService.table_select(d.unitStatus, this.unitStatus_list);
				}
			  }
            ]]
          ,request: {
            pageName: 'page' //页码的参数名称，默认：page
            ,limitName: 'size' //每页数据量的参数名，默认：limit
          }
          ,parseData: function(res){ //res 即为原始返回的数据
            return {
              "code": res.code, //解析接口状态
              "msg": res.message, //解析提示文本
              "count": res.object.total, //解析数据长度
              "data": res.object.list //解析数据列表
            }
          }
          ,response: {
            statusCode: 200 //规定成功的状态码，默认：0
            ,dataName: 'data' //规定数据列表的字段名称，默认：data
          } 
        });
        table.on('rowDouble(popup1_tblist_pua)', (obj)=>{
          this.popup1_hide();
          if(this.popup1_id==1){
            this.popup01_ss4=obj.data.unitCode;
          }

          
         });
        
      });
      
    },50);
  
  }




  popup2 = false;
  popup2_show(id?): void {
    this.popup2_id=id;
    this.popup2 = true;
    this.popup2_table();
  }
  popup2_hide(): void {
    this.popup2 = false;
    this.popup2_ss1='';
    this.popup2_ss2='';
    this.popup2_ss3=''; 
    this.popup2_ss4=''; 
  }

  popup2_ss1='';
  popup2_ss2='';
  popup2_ss3='';
  popup2_ss4='';
  popup2_id
  popup2_table(){
    if(this.popup2_id==1){//搜索时收货仓库
      this.popup2_listTable("/erp/unit/option/unitOption?unitType=WH&switchUnitId="+this.popup01_switchUnitId+"&unitCode="+this.popup2_ss1+"&unitName="+this.popup2_ss2+"&inputCode="+this.popup2_ss3+"&unitStatus="+this.popup2_ss4);
    }
  }

  popup2_listTable(url):void{
    setTimeout(()=>{ 
      layui.use(['table'], (obj)=>{
        var  table = layui.table
        
        table.render({
          elem: '#popup2_tblist_pua'
          ,height: this.utilService.height
          ,width:680
          ,url: url
          ,page: true //开启分页
          ,limit:1000
          ,limits:this.utilService.limits
          ,title: '数据表'
          ,cellMinWidth: 100
          ,cols: [[
			{title: '序号', type: 'numbers',fixed: 'left'},
            {field: 'unitCode', title: '组织代码', sort: true}
			  ,{field: 'unitId', title: '组织id',hide:true} 
			  ,{field: 'unitName', title: '组织名称'} 
			  ,{field: 'inputCode', title: '助记码'}
			  ,{field: 'telNum', title: '电话号码'}
			  ,{field: 'address', title: '地址'}
			  ,{field: 'lmCode', title: '联系人姓名'}
			  ,{field: 'unitStatus', title: '组织状态',
				templet: (d) => {
				  return this.utilService.table_select(d.unitStatus, this.unitStatus_list);
				}
			  }
            ]]
          ,request: {
            pageName: 'page' //页码的参数名称，默认：page
            ,limitName: 'size' //每页数据量的参数名，默认：limit
          }
          ,parseData: function(res){ //res 即为原始返回的数据
            return {
              "code": res.code, //解析接口状态
              "msg": res.message, //解析提示文本
              "count": res.object.total, //解析数据长度
              "data": res.object.list //解析数据列表
            }
          }
          ,response: {
            statusCode: 200 //规定成功的状态码，默认：0
            ,dataName: 'data' //规定数据列表的字段名称，默认：data
          } 
        });
        table.on('rowDouble(popup2_tblist_pua)', (obj)=>{
          this.popup2_hide();
          if(this.popup2_id==1){//搜索时收货仓库
            this.popup01_ss5=obj.data.unitCode
          }
         });
        
      });
      
    },50);
  
  }














}
